package cn.fan.redis;

import cn.fan.mapper.FundDataMapper;
import cn.fan.pojo.FundData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class FundDataRedis {
    private static final String FUNDDATAVAL = "funddata";
    private static final String FUNDDATALIST = "funddata:list";

    @Autowired
    private FundDataMapper fundDataMapper;

    @Cacheable(value = FUNDDATAVAL ,key = "#id")
    public FundData getById(long id){
        return fundDataMapper.selectById(id);
    }

    @CachePut(value = FUNDDATAVAL ,key = "#id")
    public FundData putById(long id){
        return fundDataMapper.selectById(id);
    }

    @CachePut(value = FUNDDATAVAL ,key = "#id")
    public FundData putById(long id,FundData fundData){
        return fundData;
    }

    @CacheEvict(value = FUNDDATAVAL ,key = "#id")
    public void delete(long id){}


    // list
    @Cacheable(value = FUNDDATALIST ,key = "#code")
    public List<FundData> listGetById(String code){
        QueryWrapper<FundData> queryWrapper=new QueryWrapper();
        queryWrapper.eq("code",code);
        return fundDataMapper.selectList(queryWrapper);
    }

    @CachePut(value = FUNDDATALIST ,key = "#code")
    public List<FundData> listPutById(String code){
        return listGetById(code);
    }

    @CachePut(value = FUNDDATALIST ,key = "#code")
    public List<FundData> listPutById(String code,List<FundData> list){
        return list;
    }

    @CacheEvict(value = FUNDDATALIST ,key = "#code")
    public void deleteList(String code){}

}
